<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<%@include file="/web/header.jsp" %>
<title>图片维护</title>
</head>
<body>
<button type="button" class="layui-btn" id="test1">
  <i class="layui-icon">&#xe67c;</i>上传图片
</button>
<div class="layui-upload-list">
    <table class="layui-table">
        <thead>
            <tr>
                <th width="5%">文件名</th>
                <th width="10%">图片</th>
                <th width="10%">操作</th>
            </tr>
        </thead>
        <tbody id="demoList2"></tbody>
    </table>
</div>
<script>
var code = '<%=request.getParameter("code")%>';
renderUpload('test1','/StaffUploadServlet',{code:code},function(res){
	if(res.code=='0'){
		layer.msg('上传成功');
		showPic(res.data);
	}
})
function delPic(){
	openConfirm(function(index){
		ajax('/StaffServlet',{action:'delpic',code:code},'text',function(data){
			if(data==1){
				layer.msg('删除成功');
				init();
			}else{
				layer.msg('删除失败');
			}
		})
	})
}
init();
function init(){
	ajax('/StaffServlet',{action:'get',code:code},'json',function(data){
		var image=data.image;
		if(image)
			showPic(image)
		else
			$("#demoList2").html('')
	})
}
function showPic(url){
	var html = "<tr><td>"+url+"</td><td>"
	+'<image src ="/image/'+url+'" alt="'+url+'" class="layui-upload-img">'
	+"</td><td><input type='button' class='layui-btn' onclick='delPic()' value='删除'>"
	+"</td></tr>";
	$("#demoList2").html(html);
}
</script>
</body>
</html>